We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | /* |
||
12 | function($, Module, Backbone, Bootbox, Routing, __, InfoView, ClientCredit, ClientContact, AddressView, AddressCollection) { |
||
13 | 'use strict'; |
||
14 | |||
15 | return Module.extend({ |
||
16 | regions: { |
||
17 | 'clientCredit': '#client-credit', |
||
18 | 'clientInfo': '#client-info' |
||
19 | }, |
||
20 | _renderCredit: function(options) { |
||
21 | this.app.showChildView('clientCredit', ClientCredit.getView(options)); |
||
22 | }, |
||
23 | _renderContactCollection: function(layoutView, options) { |
||
24 | layoutView.renderContactsRegion(ClientContact.getView(options)); |
||
25 | }, |
||
26 | _renderClientAddresses: function(layoutView, options) { |
||
27 | var addressCollection = new AddressCollection(options.addresses, {'id': options.id}); |
||
28 | |||
29 | var that = this; |
||
30 | |||
31 | addressCollection.on('remove', function() { |
||
32 | addressCollection |
||
33 | .fetch({reset: true, url: Routing.generate('_xhr_clients_address_list', {'id': options.id})}) |
||
34 | .done(function() { |
||
35 | layoutView.model.set('addresses', addressCollection.toArray()); |
||
36 | options.addresses = layoutView.model.get('addresses'); |
||
37 | |||
38 | layoutView.render(); |
||
39 | that._renderContactCollection(layoutView, options); |
||
40 | if (addressCollection.length > 0) { |
||
41 | layoutView.getRegion('clientAddress').show(new AddressView({collection: addressCollection})); |
||
42 | } |
||
43 | } |
||
44 | ); |
||
45 | }); |
||
46 | |||
47 | if (addressCollection.length > 0) { |
||
48 | layoutView.getRegion('clientAddress').show(new AddressView({collection: addressCollection})); |
||
49 | } |
||
50 | }, |
||
51 | _renderClientInfo: function(options) { |
||
52 | var infoView = new InfoView({ |
||
53 | model: new Backbone.Model(options) |
||
54 | }); |
||
55 | |||
56 | this.app.showChildView('clientInfo', infoView); |
||
57 | |||
58 | return infoView; |
||
59 | }, |
||
60 | initialize: function(options) { |
||
61 | this._renderCredit(options); |
||
62 | |||
63 | var infoView = this._renderClientInfo(options); |
||
64 | this.render(infoView, options); |
||
65 | |||
66 | $('#delete-client').on('click', this.deleteClient); |
||
67 | }, |
||
68 | render: function(infoView, options) { |
||
69 | this._renderContactCollection(infoView, options); |
||
70 | this._renderClientAddresses(infoView, options); |
||
71 | }, |
||
72 | deleteClient: function(event) { |
||
73 | event.preventDefault(); |
||
74 | |||
75 | var link = $(this); |
||
76 | |||
77 | Bootbox.confirm(__('client.confirm_delete'), function(confirm) { |
||
78 | if (true === confirm) { |
||
79 | $('body').modalmanager('loading'); |
||
80 | |||
81 | $.ajax({ |
||
82 | "url": link.attr("href"), |
||
83 | "dataType": "json", |
||
84 | "method": "delete" |
||
85 | }).done(function() { |
||
86 | window.document.location = Routing.generate("_clients_index"); |
||
87 | }); |
||
88 | } |
||
89 | }); |
||
90 | } |
||
91 | }); |
||
92 | } |
||
93 | ); |